﻿using System;
using Microsoft.Xna.Framework;


namespace RoboTrocity.Code {
	abstract class Item : MovableObject {
		public Item(Point _position, String _imgloc)
			: base(_position) {
			
		}

		/// <summary>
		/// This will, almost all the time, end up with the Player picking up the Item.
		/// </summary>
		/// <param name="player">The Player that picks up the Item.</param>
		public override void collideWith(Player player) {
			GetPickedUp(player);
		}

		/// <summary>
		/// Handle collision between this Item and Terrain.
		/// </summary>
		/// <param name="terrain">The Terrain that is being collided with.</param>
		public override void collideWith(Terrain terrain) {
			Vector2 movement = CollisionHandler.FindMovementOffset(Bounds, terrain.Bounds);

			if (movement.X != 0) {
				if (movement.X > 0) {
					setPositionX(terrain.Bounds.Right + 1);
				} else {
					setPositionX(terrain.Bounds.Left - Width - 1);
				}
				setVelocityX(0);
			}

			if (movement.Y != 0) {
				if (movement.Y > 0) { //colliding with ceiling
					setPositionY(terrain.Bounds.Bottom + 1);
				} else if (movement.Y < 0) {
					setPositionY(terrain.Bounds.Top - Height);
				}
				setVelocityY((int)-Velocity.Y / 2);
			}
		}

		/// <summary>
		/// What happens when the Item gets picked up by the Player.
		/// </summary>
		/// <param name="player">The Player that picks up the Item.</param>
		public abstract void GetPickedUp(Player player);
	}
}
